/**
 * @filename:UserAccountServiceImpl 2023-4-21
 * @project Wonder Java前后台分离框架  1.1.0
 * Copyright(c) 2022 Wonder Co. Ltd. 
 * All right reserved. 
 */
package com.wonder.app.service.impl;

import com.wonder.app.domain.UserAccount;
import com.wonder.app.vo.UserAccountVo;
import com.wonder.app.mapper.UserAccountDao;
import com.wonder.app.service.UserAccountService;
import com.wonder.app.request.UserAccountRequest;
import com.wonder.common.utils.StringUtils;
import com.wonder.common.utils.MessageUtils;
import com.wonder.common.common.AjaxResult;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

/**   
 * @Description:TODO(用户资金账户服务实现)
 *
 * @version: 1.1.0
 * @author: Wonder
 * 
 */
@Service
public class UserAccountServiceImpl  extends ServiceImpl<UserAccountDao, UserAccount> implements UserAccountService  {

    /**
     * 验证用户资金账户信息
     * 
     * @param userAccount
     * @param type
     * @return String
     */
    @Override
    public String validate(UserAccount userAccount,String type){
    
    
       return "";
    }
    
    
    /*
	 * 分页返回，自定义多表分页数据返回
	 */
	@Override 
    public IPage<UserAccountVo> selectUserAccountVoList(UserAccountRequest request, Page<UserAccountVo> page){
	    QueryWrapper<UserAccountVo> queryWrapper = new QueryWrapper<>();
	    
	    if (null != request.getUid()) {
	       queryWrapper.eq("a.uid", request.getUid());
	      }               
             
        if (StringUtils.hasText(request.getUser_real_name())) {
			    queryWrapper.like("b.real_name", request.getUser_real_name()); 
		    } 
             
        if (StringUtils.hasText(request.getUser_caller())) {
			    queryWrapper.eq("b.caller", request.getUser_caller());
		    } 
             
	    if (null != request.getAgent()) {
	       queryWrapper.eq("a.agent", request.getAgent());
	      }               
             
        if (StringUtils.hasText(request.getUser_name())) {
			    queryWrapper.like("b.name", request.getUser_name()); 
		    } 
             
        if (StringUtils.hasText(request.getUser_phone())) {
			    queryWrapper.like("b.phone", request.getUser_phone()); 
		    } 
             
        
		queryWrapper.orderByDesc("a.uid");	
		if(StringUtils.hasText(request.getAccount_type()) && request.getAccount_type().equals("simulate"))
			return this.baseMapper.getSimulateUserAccountVoList(page, queryWrapper);
		return this.baseMapper.getUserAccountVoList(page, queryWrapper);

    }
    
    /**
	 * 返回VO单个数据
	 */
	@Override 
	public UserAccountVo getVoById(Long uid){
	    QueryWrapper<UserAccountVo> queryWrapper=new QueryWrapper<UserAccountVo>().eq("a.uid", uid);
		return this.baseMapper.getUserAccountVoList(queryWrapper);
	}
	
    /**
	 * Description:用户资金账户分页返回
	 * @param request //检索条件
	 * @param page //分页参数
	 * @return IPage<UserAccount>   //分页记录
	 */
	@Override 
	public IPage<UserAccount> selectList(UserAccountRequest request, Page<UserAccount> page){
	    LambdaQueryWrapper<UserAccount> lambdaQueryWrapper = new LambdaQueryWrapper<>();
	    
	    if (null != request.getUid()) {
	       lambdaQueryWrapper.eq(UserAccount::getUid, request.getUid());
	      }               
             
        if (StringUtils.hasText(request.getUser_real_name())) {
			    lambdaQueryWrapper.like(UserAccount::getUser_real_name, request.getUser_real_name()); 
		    } 
             
        if (StringUtils.hasText(request.getUser_caller())) {
			    lambdaQueryWrapper.eq(UserAccount::getUser_caller, request.getUser_caller());
		    } 
             
	    if (null != request.getAgent()) {
	       lambdaQueryWrapper.eq(UserAccount::getAgent, request.getAgent());
	      }               
             
        if (StringUtils.hasText(request.getUser_name())) {
			    lambdaQueryWrapper.like(UserAccount::getUser_name, request.getUser_name()); 
		    } 
             
        if (StringUtils.hasText(request.getUser_phone())) {
			    lambdaQueryWrapper.like(UserAccount::getUser_phone, request.getUser_phone()); 
		    } 
             
        
		lambdaQueryWrapper.orderByDesc(UserAccount::getUid);	
		Page<UserAccount> selectPage = this.baseMapper.selectPage(page, lambdaQueryWrapper);
		return selectPage;
    }
        
    
	
}